package com.tenement.common;


import com.alibaba.fastjson.JSON;
import com.mybatisflex.core.tenant.TenantFactory;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import java.util.List;

public class TenantFactoryx implements TenantFactory {


    @Override
    public Object[] getTenantIds() {
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        assert attributes != null;
        Object tenantId = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
        List<Long> tenantIds = JSON.parseArray(JSON.toJSONString(tenantId), Long.class);
        return tenantIds.toArray();
    }

}
